home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / X11R4 / cmds / X / ddx / dec / qdss / libtl / tldashedline.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-11-27  |  3.9 KB  |  126 lines

  1. /***********************************************************
  2. Copyright 1989 by Digital Equipment Corporation, Maynard, Massachusetts,
  3. and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
  4.  
  5.                         All Rights Reserved
  6.  
  7. Permission to use, copy, modify, and distribute this software and its 
  8. documentation for any purpose and without fee is hereby granted, 
  9. provided that the above copyright notice appear in all copies and that
  10. both that copyright notice and this permission notice appear in 
  11. supporting documentation, and that the names of Digital or MIT not be
  12. used in advertising or publicity pertaining to distribution of the
  13. software without specific, written prior permission.  
  14.  
  15. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  16. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  17. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  18. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  19. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  20. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  21. SOFTWARE.
  22.  
  23. ******************************************************************/
  24.  
  25. #define DASHED
  26. #define POLYSEGMENT tlPolySegmentDashed
  27. #define POLYLINES tlPolylinesDashed
  28. /* compile dashed versions of routines */
  29. #include "tlline.c"
  30.  
  31. static GCPtr (_DashMap_[NPLANES+1]) = {0};
  32. #define DashMap (_DashMap_+1)
  33. extern int Nplanes;
  34.  
  35. /* return plane containing installed dash pattern */
  36. int
  37. InstallDashes(pGC)
  38.      GCPtr pGC;
  39. {
  40.     register unsigned short *p;
  41.     int planeNum;
  42.     int length = GC_DASH_LENGTH(pGC);
  43.     int nDashPairs;
  44.     register int odd, x;
  45.     int oddLength;
  46.     unsigned char *pDash;
  47.     int maxDashPerBlock;
  48.     planeNum = GC_DASH_PLANE(pGC);
  49.     if (DashMap[planeNum] == pGC)
  50.     return 1<<planeNum;
  51.     for (planeNum = Nplanes; ; ) {
  52.     if (--planeNum < 0) {
  53.         static PlaneToRemove = 0;
  54.         /* throw out a "random" plane */
  55.         planeNum = PlaneToRemove;
  56.         PlaneToRemove++;
  57.         if (PlaneToRemove >= Nplanes) PlaneToRemove = 0;
  58.         break;
  59.     }
  60.     if (DashMap[planeNum] == 0)
  61.         break;
  62.     }
  63.     DashMap[planeNum] = pGC;
  64.     GC_DASH_PLANE(pGC) = planeNum;
  65.  
  66.     if (pGC->numInDashList & 1) {
  67.     oddLength = length;
  68.         odd = 0;
  69.     }
  70.     else
  71.     odd = -1;
  72.     if (length > 1024) return 0; /* should never happen */
  73.  
  74.     SETTRANSLATEPOINT(0, 0);
  75.     Need_dma(13);
  76.     *p++ = JMPT_SET_MASKED_ALU;
  77.     *p++ = 1<<planeNum;
  78.     *p++ = LF_SOURCE | FULL_SRC_RESOLUTION;
  79.     *p++ = JMPT_RESETCLIP;
  80.     *p++ = JMPT_SETCOLOR;
  81.     *p++ = 0;
  82.     *p++ = JMPT_SOLIDSPAN;
  83.     *p++ = 0;
  84.     *p++ = DASH_Y;
  85.     *p++ = length;    
  86.     *p++ = JMPT_SETCOLOR;
  87.     *p++ = 0xFFFF;
  88.     *p++ = JMPT_SOLIDSPAN;
  89.     Confirm_dma();
  90.     x = - (pGC->dashOffset % length);
  91.     pDash = (unsigned char *)pGC->dash;
  92.     nDashPairs = pGC->numInDashList;
  93.     maxDashPerBlock = MAXDMAWORDS/6;
  94.     if (odd < 0) nDashPairs >>= 1;
  95.     do {
  96.     register int i = min(maxDashPerBlock, nDashPairs);
  97.     nDashPairs -= i;
  98.     Need_dma(6*i);
  99.     while ( --i >= 0) {
  100.         int w = *pDash++;
  101.          /*
  102.           * If numInDashList is odd (i.e. odd >= 0), then protocol says
  103.           * to concatenate the dash list with itself. So the even dashes
  104.           * are drawn as normal. However, the odd dashes become the
  105.           * even dashes of the second (concatenated) half, which is
  106.           * oddLength beyond the actual position of x.
  107.           */
  108.          int xx = odd > 0 ? x + oddLength : x;
  109.          /*The dash pattern is logically rotated left by pGC->dashOffset.*/
  110.          /*So, each dash is written twice: First offset by -dashOffset...*/
  111.          *p++ = xx & 0x3FFF;
  112.          *p++ = DASH_Y;
  113.          *p++ = w;
  114.          /* ... then each dash is offset by length-dashOffset */
  115.          *p++ = xx + length;
  116.          *p++ = DASH_Y;
  117.          *p++ = w;
  118.          x += w;
  119.          if (odd < 0) x += *pDash++; /* skip odd dashes */
  120.          else odd = 1 - odd;
  121.      }
  122.      Confirm_dma();
  123.      } while (nDashPairs > 0);
  124.     return 1<<planeNum;
  125. }
  126.